package com.sinaapp.kjWeb.action;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import net.sf.json.JSONObject;
import org.apache.http.Consts;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sinaapp.kjWeb.util.ConfigUtils;



/*
 *auth:徐疆
 *date 2014-1-12 下午4:15:24
 */
public class HackLoginAction extends Action{
	public static Logger logger=LoggerFactory.getLogger(HackLoginAction.class);
	private String userId;
	public HackLoginAction() {
		super("hack登入");
	}

	public HackLoginAction(String userId) {
		super("hack登入");
		this.userId = userId;
	}
	
	@Override
	public void doAction() {
		
		HttpGet httpget = new HttpGet("http://218.22.63.5:8082/Home/Index?EmpID="+userId);
		InputStream is=null;
		try {
			CloseableHttpResponse loginResponse = this.getHttpClient().execute(httpget);
			int status=loginResponse.getStatusLine().getStatusCode();
			if(status==200){
				logger.debug(userId+"登录成功");
				return;
			}
			throw new RuntimeException(userId+"登录失败");
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("登录出错了",e);
			throw new RuntimeException("登录失败");
		}finally{
			if(is!=null){
				try {
					is.close();
				} catch (IOException e) {
				}
			}
		}
	}
	
}

